<?php 
//var_dump($this->rsHanghoadv);
?>

<header class="panel-heading">
	<strong> Danh Mục Hàng Hóa Dịch Vụ </strong>
</header>
<div class="panel-body">
	<div class="adv-table editable-table ">
		<div class="clearfix">
			<div class="btn-group">
				<a class="btn btn-success" href="<?php echo _BASE_URL?>quantri/hanghoadv/them">
					Thêm hàng hóa dịch vụ <i class="icon-plus"></i>
				</a>
				
			
			</div>
			
			<div class="btn-group pull-right">
				<button data-toggle="dropdown" class="btn dropdown-toggle">Xuất dữ liệu <i class="icon-angle-down"></i></button>
				<ul class="dropdown-menu pull-right">
					<li><a href="#">Xem in</a></li>
					<li><a href="#">Xuất PDF</a></li>
					<li><a href="#">Xuất Excel</a></li>
				</ul>
			</div>
		</div>
		<div class="space15"></div>
	  <div role="grid" class="dataTables_wrapper form-inline" id="editable-sample_wrapper">
		
		<table id="editable-sample" class="table table-striped table-hover table-bordered dataTable" aria-describedby="editable-sample_info">
			<thead>
				<tr role="row">
					<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 10px;" aria-label="Username">Stt</th>
					<th class="sorting" role="columnheader" rowspan="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 150px;" >Tên Hàng</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 50px;" >Nhóm Hàng</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 50px;" >ĐVT</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 80px;">Giá Mua</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 78px;" >Giá Bán</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 78px;" >Mã Vạch</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 78px;" >Ngày Tạo</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 50px;">Trạng Thái</th>
					<th class="sorting" role="columnheader" tabindex="0" aria-controls="editable-sample" rowspan="1" colspan="1" style="width: 70px;" ></th>
				</tr>
		  </thead>
		  
		  <tbody role="alert" aria-live="polite" aria-relevant="all">
			  <?php 
			  $stt = 0;
			  foreach($this->rsHanghoadv as $rs) { 
				$stt++;
				?>
			  <tr>
				  
				  <td class="  sorting_1"><?php echo $stt ?></td>
				  <td class="  sorting_1"><?php echo $rs['Ten'] ?></td>	
				  <td class="  sorting_1"><?php echo $rs['NhomHHDV'] ?></td>	
				  <td class="  sorting_1"><?php echo $rs['DVT'] ?></td>
				  <td class="  sorting_1"><?php echo $rs['GiaMua'] ?></td>
				  <td class="  sorting_1"><?php echo $rs['GiaBan'] ?></td>
				  <td class="  sorting_1"><?php echo $rs['MaVach'] ?></td>
				  <td class=" "> <?php echo date_format(date_create($rs['NgayTao']), 'd/m/Y') ?></td>				  
				  <td style="text-align: center" class="center"> 
				  	<a href="javascript:void(0)" class="<?php echo ($rs['TrangThai']==1) ? '' : 'red' ?>">
				  		<i class="<?php echo ($rs['TrangThai']==1) ? 'icon-check-sign' : 'icon-lock' ?>"></i>
				  	</a> 
				  </td>
				  <td style="text-align: center">
				  	<a class="ograne edit" href="<?php echo _BASE_URL?>quantri/hanghoadv/sua/id/<?php echo $rs['Id'] ?>" idHanghoadv="<?php echo $rs['Id'] ?>"><i class="icon-edit"></i></a>
			     	<a class="red xoa" href="javascript:;" class="delete" data="<?php echo $rs['Id']?>" ><i class="icon-remove"></i></a></td>
			  </tr>
			  <?php } ?>
		</tbody>
		</table>
  </div>
	</div>
</div>        


<!-- END JAVASCRIPTS -->
<script> 
EditableTable.init();
				
	  ///////////////////////////////////////////////////////////
	  // Xoa
	  $(".xoa").click(function(){

		  if (confirm("Bạn có muốn xóa dòng này không ?") == false) {
              return;
          }
          
		var deleteUrl = "<?php echo _BASE_URL?>/quantri/hanghoadv/xoa";
		var idHanghoadv = $(this).attr('data');
		var formData = {id: idHanghoadv}; //Array
		
		var tr = $(this).closest('tr');
		
		$.ajax({
			  url : deleteUrl,
			  type: "POST",
			  data : formData,
			  success: function(data, textStatus, jqXHR)
			  {
				  alert('Xóa thành công!');
				  deleteRowofTable(tr);
			  },
			  error: function (jqXHR, textStatus, errorThrown)
			  {
				  alert('Xóa thất bại');
			  }
			});
			
	  });

	  
	  function deleteRowofTable(tr)
	  {
		tr.css("background-color","#FF3700");
			tr.fadeOut(400, function(){
			tr.remove();
		});
	  }

	 
</script>